<template>
	<view class="uni_box home">
		<navbar title='资产明细' :yin="false">
		</navbar>
		<view class="content">
			<view class="Asset-detail">
				<view class="Asset-item">
					<image class="bicon" :src="items.currency.logo" />
					<text class="bname">{{items.currency.name}}</text>
					<view class="assetitem" @click="getbill()">
						<image class="asseticon" src="/static/img/mthree.png" />
						<text>账单</text>
					</view>
				</view>
				<view class="Asset-itemtwo">
					<text class="nums">{{ formatNumber(items.money) }}</text>
					<view class="Transactionitems">
						<text class="numstwo">{{ formatNumber(Equivalent)+'USD' }}</text>
					
					</view>
				</view>
				
			</view>
			<view class="zitwo">
				<text class="Transaction-records">交易记录</text>
				<view class="Transaction-list">
					<view class="Transaction-item" v-for="(item,index) in list" :key="index">
						<view class="mleft">
							<text class="Transaction-type">{{ item.log_type_text }}</text>
							<text class="Transaction-time">{{item.created_at}}</text>
						</view>
						<text class="Transaction-price">{{ item.trade_inc==1?'+':'-'+item.amount }}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id:'',
				log_type:'',
				items:{},
				list: [],

				page: 1,
				last_page: 1,
				limit: 10,
				status: 'loadmore',
				Equivalent:''
			}
		},
		onLoad(option) {
			this.id = option.id
			this.items = JSON.parse(option.items)
			// console.log(this.items)
			let locale = uni.getStorageSync('locale')
			this.Equivalent = Number(this.items.money)/Number(locale.rate)
			// this.getmoneylog();
			this.getList()
		},
		onShow() {
		},
		onReachBottom: function() {
			this.loadmore();
		},
		methods: {
			async getList(){
				let list = await this.$u.api.money_log({
					page:this.page,
					limit:this.limit,
					currency:this.id,
					log_type:'all'
				});
				console.log(list)
				this.last_page = list.last_page;
				this.list = this.page == 1 ? list.data : [...this.list, ...list.data];
				if (this.last_page == this.page || list.data == '') {
					this.status = 'nomore';
				}
			},
			loadmore() {
				let page = this.page;
				let last_page = this.last_page;
				if (page < last_page) {
					this.page++;
					this.getList();
				}
			},
			timestampToTime(timestamp) {
				const date = new Date(Number(timestamp))
				const Y = date.getFullYear() + '/'
				const M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '/'
				const D = (date.getDate() < 10 ? '0'+(date.getDate()) : date.getDate()) + ' '
				const h = (date.getHours() < 10 ? '0'+(date.getHours()) : date.getHours()) + ':'
				const m = (date.getMinutes() < 10 ? '0'+(date.getMinutes()) : date.getMinutes()) + ':'
				const s = (date.getSeconds() < 10 ? '0'+(date.getSeconds()) : date.getSeconds())
				return Y+M+D+h+m+s
			},
			getbill(){
				this.navrouter("/pages/TPage/billPage?id="+this.id);
			},
			formatNumber(num) {
				// console.log(typeof num)
				// 将数字转换为字符串
				
				var numStr = ''
				if(typeof num == 'number'){
					numStr = num.toString();
				}else{
					numStr = num;
				}
				if(!this.containsDecimal(numStr)){
					return Number(num)
				}
				
				// 使用正则表达式检查小数点后是否全为0
				const isDecimalAllZeros = /^\d+(\.\d{6})?0{1,}$/.test(numStr);
				// 根据条件格式化数字
				return isDecimalAllZeros ? Number(num).toFixed(2) : Number(num).toFixed(6);
			},
			containsDecimal(str) {
				return /\d+\.\d+/.test(str);
			},
		}
	}
</script>

<style lang="scss" scoped>
	page{
		background-color: #fff;
	}
	.content{
		background-color: #fff;
		.Asset-detail{
			margin: 46rpx 40rpx;
			padding: 40rpx 30rpx;
			background: #F8F8F8;
			border-radius: 20rpx;
			.Asset-item{
				display: flex;
				flex-direction: row;
				align-items: center;
				.bicon{
					margin-right: 12rpx;
					width: 44rpx;
					height: 44rpx;
					
				}
				.bname{
					font-family: Source Han Sans CN;
					font-weight: bold;
					font-size: 30rpx;
					color: #000000;
				}
			}
			.Asset-itemtwo{
				margin-left: 56rpx;
				display: flex;
				flex-direction: column;
				.nums{
					font-family: Source Han Sans CN;
					font-weight: 500;
					font-size: 40rpx;
					color: #000000;
					display: block;
					margin: 20rpx 0 10rpx;
				}
				.numstwo{
					font-family: Source Han Sans CN;
					font-weight: 400;
					font-size: 28rpx;
					color: #999999;
				}
			}
		}
		.zitwo{
			padding: 0 60rpx;
			.Transaction-records{
				font-family: Source Han Sans CN;
				font-weight: bold;
				font-size: 30rpx;
				color: #000000;
				margin-bottom: 50rpx;
				display: block;
			}
			.Transaction-list{
				.Transaction-item{
					border-bottom: 2rpx solid #F7F7F7;;
					padding: 23rpx 0;
					display: flex;
					flex-direction: row;
					align-items: center;
					.mleft{
						width: 80%;
						display: flex;
						flex-direction: column;
						.Transaction-type{
							font-family: Source Han Sans CN;
							font-weight: 400;
							font-size: 24rpx;
							color: #000000;
						}
						.Transaction-time{
							margin-top: 10rpx;
							font-family: Source Han Sans CN;
							font-weight: 400;
							font-size: 20rpx;
							color: #000000;
						}
					}
					.Transaction-price{
						margin-left: auto;
						font-family: Source Han Sans CN;
						font-weight: bold;
						font-size: 30rpx;
						color: #32BE67;
					}
				}
			}
		}
		// padding-bottom: 150rpx;
	}
	.Transactionitems{
		display: flex;
		flex-direction: row;
		align-items: center;
	}
	.assetitem{
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		margin-left: auto;
		.asseticon{
			width: 42rpx;
			height: 42rpx;
			margin-bottom: 8rpx;
		}
		text{
			font-family: Source Han Sans CN;
			font-weight: 400;
			font-size: 24rpx;
			color: #000000;
		}
	}
</style>
